﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NineMine.DataModel
{
    public class NineMineDataContext : DbContext
    {
        public NineMineDataContext() : base() { }

        public NineMineDataContext(string connectionString) : base(connectionString) { }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Issue>().HasOptional<Issue>(e => e.Parent).WithOptionalDependent().WillCascadeOnDelete(false);
            modelBuilder.Entity<IssueRelation>().HasRequired<Issue>(e => e.IssueFrom).WithRequiredPrincipal().WillCascadeOnDelete(false);
            modelBuilder.Entity<IssueRelation>().HasRequired<Issue>(e => e.IssueTo).WithRequiredPrincipal().WillCascadeOnDelete(false);
            modelBuilder.Entity<TimeEntry>().HasRequired<Issue>(e => e.Issue).WithRequiredPrincipal().WillCascadeOnDelete(false);           
        }

        public DbSet<Attachment> Attachments { get; set; }

        public DbSet<AuthSource> AuthSources { get; set; }

        public DbSet<Board> Boards { get; set; }

        public DbSet<Change> Changes { get; set; }

        public DbSet<ChangeSet> ChangeSets { get; set; }

        public DbSet<Comment> Comments { get; set; }

        public DbSet<CustomField> CustomFields { get; set; }

        public DbSet<CustomValue> CustomValues { get; set; }

        public DbSet<Document> Documents { get; set; }

        public DbSet<EnabledModule> EnabledModules { get; set; }

        public DbSet<Enumeration> Enumerations { get; set; }

        public DbSet<Issue> Issues { get; set; }

        public DbSet<IssueCategory> IssueCategories { get; set; }

        public DbSet<IssueRelation> IssueRelations { get; set; }

        public DbSet<IssueStatus> IssueStatuses { get; set; }

        public DbSet<Journal> Journals { get; set; }

        public DbSet<JournalDetail> JournalDetails { get; set; }

        public DbSet<Member> Members { get; set; }

        public DbSet<MemberRole> MemberRoles { get; set; }

        public DbSet<Message> Messages { get; set; }

        public DbSet<News> News { get; set; }

        public DbSet<OpenIdAuthenticationAssociation> OpenIdAuthenticationAssociations { get; set; }

        public DbSet<OpenIdAuthenticationNonce> OpenIdAuthenticationNonces { get; set; }

        public DbSet<Project> Projects { get; set; }

        public DbSet<Query> Queries { get; set; }

        public DbSet<Repository> Repositories { get; set; }

        public DbSet<Role> Roles { get; set; }

        public DbSet<Setting> Settings { get; set; }

        public DbSet<TimeEntry> TimeEntries { get; set; }

        public DbSet<Token> Tokens { get; set; }

        public DbSet<Tracker> Trackers { get; set; }

        public DbSet<User> Users { get; set; }

        public DbSet<UserPreference> UserPreferences { get; set; }

        public DbSet<Version> Versions { get; set; }

        public DbSet<Watcher> Watchers { get; set; }

        public DbSet<Wiki> Wikis { get; set; }

        public DbSet<WikiContent> WikiContents { get; set; }

        public DbSet<WikiContentVersion> WikiContentVersions { get; set; }

        public DbSet<WikiPage> WikiPages { get; set; }

        public DbSet<WikiRedirect> WikiRedirects { get; set; }

        public DbSet<Workflow> Workflows { get; set; }
    }
}
